import { createWebHistory, createRouter } from 'vue-router'

//导入组件
import Home from '../views/Home.vue'
import Login from '../views/user/Login.vue'
//配置路径关系
const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home,
    children: [
      { path: '/', component: () => import('../views/page/Home.vue') },
      { path: '/carowner', component: () => import('../views/page/CarOwner.vue') },
      { path: '/booktickets', component: () => import('../views/page/BookTickets.vue') },
      { path: '/delivery', component: () => import('../views/page/Delivery.vue') },
      { path: '/my', component: () => import('../views/page/My.vue') },
    ]
  },
  { path: '/test', component: () => import('../views/test.vue') },
  { path: '/login', component: Login },
  { path: '/dingding', component: () => import('../views/user/Dingding.vue') },
  { path: '/face', component: () => import('../views/user/Face.vue') },
  { path: '/setting', component: () => import('../views/user/Setting.vue') },
  { path: '/account', component: () => import('../views/user/SettingsPage/Account.vue') },
  { path: '/agreement', component: () => import('../views/user/SettingsPage/Agreement.vue') },
  { path: '/authorization', component: () => import('../views/user/SettingsPage/Authorization.vue') },
  { path: '/common', component: () => import('../views/user/SettingsPage/Common.vue') },
  { path: '/guide', component: () => import('../views/user/SettingsPage/Guide.vue') },
  { path: '/language', component: () => import('../views/user/SettingsPage/Language.vue') },
  { path: '/pay', component: () => import('../views/user/SettingsPage/Pay.vue') },
  { path:'/personal', component: () => import('../views/user/SettingsPage/Personal.vue') },
  { path: '/cancelAccount', component: () => import('../views/user/SettingsPage/AccountPage/CancelAccount.vue') },
  { path: '/information', component: () => import('../views/user/SettingsPage/AccountPage/Information.vue') },
  { path: '/installment', component: () => import('../views/user/SettingsPage/AccountPage/Installment.vue') },
  { path: '/love', component: () => import('../views/user/SettingsPage/AccountPage/Love.vue') },
  { path: '/updatePassword', component: () => import('../views/user/SettingsPage/AccountPage/UpdatePassword.vue') },
  { path: '/updatePhone', component: () => import('../views/user/SettingsPage/AccountPage/UpdatePhone.vue') },
  { path: '/idCard', component: () => import('../views/user/SettingsPage/AccountPage/InformationPage/IdCard.vue') },
  { path: '/userMessage', component: () => import('../views/page/UserMessage.vue') },
  { path: '/driverMessage', component: () => import('../views/page/DriverMessage.vue') },
  { path: '/order', component: () => import('../views/cart/Order.vue') },
]

//将创建的配置关系挂载到router实例上
const router = createRouter({
  history: createWebHistory(),
  routes
})

// router.beforeEach((to, from, next) => {
//   var reslist = ['/login', '/register', '/home']
//   if (reslist.indexOf(to.path) == -1) {
//     var token = localStorage.getItem('token')
//     token = 123
//     if (token) {
//       //验证是否在权限列表中
//       var menulist = localStorage.getItem('mpromition')
//       if (menulist) {
//         var mlist = JSON.parse(menulist)
//         if (mlist.indexOf(to.path) >= 0) {
//           next()
//         } else {
//           alert("无权访问此页面")
//           next({ "name": 'Login' })
//         }
//       } else {
//         alert("无权访问")
//       }

//     } else {
//       next({ "name": 'Login' })
//     }
//   }
//   next()
// })

export default router